<?php


if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class m_hewan extends CI_Model {


	function ambil() {
		$this->db->select("periksa_hewan.id_periksa, pemilik_hewan.nama, periksa_hewan.jenis_hewan, periksa_hewan.berat, periksa_hewan.umur, user.nama as namapemeriksa");
		$this->db->select("DATE_FORMAT(periksa_hewan.tgl_periksa, '%e %M %Y') as tgl_periksa", FALSE);
		$this->db->from('periksa_hewan');
		$this->db->join('pemilik_hewan', 'periksa_hewan.id_pemilik_hewan=pemilik_hewan.id_pemilik_hewan');
		//$this->db->join('periksa', 'hewan.id_hewan=periksa.id_hewan');
		$this->db->join('user', 'periksa_hewan.id_user=user.id_user');
		$ambil = $this->db->get();
		if ($ambil->num_rows() > 0) {
			foreach ($ambil->result() as $data) {
				$hasil[] = $data;
			}
			return $hasil;
		}
	}
	
	function tambahpemilik($data = '') {
		$this -> db -> trans_start();
		$this -> db -> insert('pemilik_hewan', $data);
		$this -> db -> trans_complete();
		return $this -> db -> trans_status();
	}

	function tambahperiksa($data = '') {
		$this -> db -> trans_start();
		$this -> db -> insert('periksa_hewan', $data);
		$this -> db -> trans_complete();
		return $this -> db -> trans_status();
	}

	function tambahhewan($data = '') {
		$this -> db -> trans_start();
		$this -> db -> insert('periksa_hewan', $data);
		$this -> db -> trans_complete();
		return $this -> db -> trans_status();
	}

	function ambil2(){
		$ambil = $this->db->query("select pemilik_hewan.nama, periksa_hewan.jenis_hewan, periksa_hewan.berat, periksa_hewan.umur, user.nama as namapemeriksa, DATE_FORMAT(periksa_hewan.tgl_periksa, '%e %M %Y') as tgl_periksa 
			from periksa_hewan
			join pemilik_hewan on pemilik_hewan.id_pemilik_hewan = periksa_hewan.id_pemilik_hewan
			join user on periksa_hewan.id_user = user.id_user");
		return $ambil->result();
	}

	function hapus($a) {
		$this->db->trans_start();
		$this->db->delete('periksa_hewan', array('id_periksa' => $a));
		//$this->db->delete('hewan', array('id_hewan' => $a));
		$this->db->trans_complete();
		return;
	}

	function ambilbyid($id="") {
		$ambil = $this->db->get_where('periksa_hewan', array('id_periksa' => $id));
		return $ambil;
	}


}

